<?php
defined('_JEXEC') or die('Restricted access');

class YOSCreateDB {
	function create () {
		
		/* create tables */
		$database = JFactory::getDBO(); 
		/* create tables new crawler */
		$query = "CREATE TABLE IF NOT EXISTS `#__yos_news_crawler` (
				  `id` int(11) NOT NULL auto_increment,
				  `link` text NOT NULL,
				  `category` tinyint(3) NOT NULL default '0',
				  `title` varchar(255) NOT NULL,
				  `description` text NOT NULL,
				  `url` varchar(255) NOT NULL default '0',
				  `sectionid` int(11) unsigned NOT NULL default '0',
				  `catid` int(11) unsigned NOT NULL default '0',
				  `catname` varchar(255) NOT NULL,
				  `content_type` varchar(32) NOT NULL,
				  `input_format` int(11) NOT NULL default '0',
				  `comment` int(11) NOT NULL default '0',
				  `checked_out` int(11) NOT NULL default '0',
				  `checked_out_time` datetime NOT NULL default '0000-00-00 00:00:00',
				  `published` tinyint(3) NOT NULL default '0',
				  `publish_time` int(11) unsigned NOT NULL default '0',
				  `publish_down` int(11) unsigned NOT NULL default '0',
				  `last_update` datetime NOT NULL default '0000-00-00 00:00:00',
				  `time_update` int(11) unsigned NOT NULL default '0',
				  `numbercontent` int(11) unsigned NOT NULL default '0',
				  `created_by` int(11) NOT NULL default '0',
				  `according_to` varchar(255) NOT NULL,
				  `get_img` tinyint(3) NOT NULL default '0',
				  `find_replace_intro` text NOT NULL,
				  `find_replace_intro_afterencode` text NOT NULL,
				  `find_replace_full` text NOT NULL,
				  `find_replace_full_afterencode` text NOT NULL,
				  `access` int(11) unsigned NOT NULL default '0',
				  `keyword` text NOT NULL,
				  `error_counter` int(11) NOT NULL default '0',
				  `error_msg` text NOT NULL,
				  `ads` text NOT NULL,
				  `catads` tinyint(3) NOT NULL default '0',
				  `readmore` tinyint(3) NOT NULL default '0',
				  `keysave` text NOT NULL,
				  `cut_content` tinyint(3) NOT NULL default '0',
				  `numberword` int(11) NOT NULL default '0',
				  `resizeimage` tinyint(3) NOT NULL default '0',
				  `maxpixel` int(11) NOT NULL default '0',
				  `getlink_reg` text NOT NULL,
				  `gettitle_reg` text NOT NULL,
				  `getintro_reg` text NOT NULL,
				  `getfull_reg` text NOT NULL,
				  `dataway` tinyint(3) NOT NULL default '0',
				  `getlink_sub` tinyint(3) NOT NULL default '0',
				  `gettitle_sub` tinyint(3) NOT NULL default '0',
				  `getintro_sub` tinyint(3) NOT NULL default '0',
				  `getfull_sub` tinyint(3) NOT NULL default '0',
				  `pid` int(11) NOT NULL default '0',
				  `find_replace_plugin` text NOT NULL,
				  `find_replace_plugin_afterencode` text NOT NULL,
				  `t_from` varchar(255) NOT NULL,
				  `t_to` varchar(255) NOT NULL,
				  `nextpage_reg` text NOT NULL,
				  `nextpage_sub` tinyint(3) NOT NULL default '0',
				  `pagebreak` tinyint(3) NOT NULL default '1',
				  `pagebreak_reg` text NOT NULL,
				  `pagebreak_sub` tinyint(3) NOT NULL default '0',
				  `find_replace_links` text NOT NULL,
				  `validate_cookie` tinyint(3) NOT NULL default '0',
				  `title_ext` varchar(255) NOT NULL,
				  `title_ext_pos` tinyint(3) NOT NULL default '0',
				  `keyword_unpublish` text NOT NULL,
				  `rewrite` tinyint(3) NOT NULL default '0',
				  `front_page` tinyint(3) NOT NULL,
					`front_page_keyword` text NOT NULL,
				  PRIMARY KEY  (`id`)
				) ENGINE=MyISAM  DEFAULT CHARSET=utf8 ;";
		
		$database->setQuery($query);
		if(!$database->query())
			return false;
			
		/* create tables content link */
		$query = "CREATE TABLE IF NOT EXISTS `#__yos_content_link` (
				  `id` int(11) NOT NULL auto_increment,
				  `link` varchar(255) NOT NULL,
				  `title` varchar(255) NOT NULL,
				  `sectionid` int(11) NOT NULL default '0',
				  `catid` int(11) NOT NULL default '0',
				  `catname` varchar(255) NOT NULL,
				  `articleid` int(11) NOT NULL,
				  PRIMARY KEY  (`id`)
				) ENGINE=MyISAM DEFAULT CHARSET=utf8;";
		
		$database->setQuery($query);
		if(!$database->query())
			return false;
			
		return true;
	}
}